<?php
namespace control;
/*
*财务会计-工资表类
*/

class salaryClass extends adIndexClass
{
    private const page = 'salary';
    private const table = 'work_sign_record';
    private const title = '工资表';

    /**
     * 字段初始化
     */
    public function fieldInit($fun): array
    {
        switch ($fun) {
            default:
                $tr = [
                    'month'          => [
                        'name'  => "月份",
                        'width' => 100,
                        'sort' => 1,
                    ],
                    'baseMoney'  => [
                        'name'  => '基本工资',
                        'width' => 200,
                    ],
                    'jobMoney'         => [
                        'name'  => '岗位工资',
                        'width' => 200,
                    ],
                    'decMoney'          => [
                        'name'  => '考勤扣款',
                        'width' => 150,
                    ],
                    'fullAttendance'          => [
                        'name'  => '全勤奖',
                        'width' => 150,
                    ],
                    'performance'          => [
                        'name'  => '绩效工资',
                        'width' => 150,
                    ],
                    'insure'          => [
                        'name'  => '社保扣款',
                        'width' => 150,
                    ],
                    'providentFund'          => [
                        'name'  => '公积金扣款',
                        'width' => 150,
                    ],
                    'personalTax'          => [
                        'name'  => '个税扣款',
                        'width' => 150,
                    ],
                    'payMoney'          => [
                        'name'  => '实发小计',
                        'width' => 150,
                    ]
                ];
        }
        return $tr;
    }

    /*列表页-查询条件*/
    public function homeOptions($isAsync = true)
    {
        //生成查询表单
        $html = $this->tableShow([
            [
                [
                    "月份" => text(array("name" => "moon", 'laydate' => ['type' => 'month','range'=>'~'])),
                ]
            ]
        ],1);
        //返回
        if (!$isAsync) {
            return $html;
        } else {
            return json_encode(['html' => $html], 320);
        }
    }

    /*列表-查询条件*/
    public function home()
    {
        $html = $this->homeOptions(false);
        //控件
        $button = "";
        if ($this->power(self::page, "edit")) {
            $button .= "<span class='spanButton li-btn-blue-bg' onclick=\"newIframe('凭证配置',root+'control/adIndex.html?cla=salary&fun=setting')\">凭证配置</span>\n";
        }
        if ($this->power(self::page, "export")) {
            $button .= "  <a href='" . root . "control/adIndex.html?cla=" . $this->get('cla') . "&fun=exportData'><span class='spanButton'>导出</span></a>\n";
        }
        //返回
        return $this->homeFun($this->search($html, layout: 'pop', toolButton: $button));
    }

    /*客户列表-查询结果*/
    public function homeSearch()
    {
        //like查询数组
        $like = array(
        );
        //全等查询数组
        $equal = array(
            "isPay" => 1,
        );
        $and = "";
        if ($this->post('moon')) {
            $arr = explode('~', $this->post('moon'));
            $arr[0] = trim($arr[0]);
            $arr[1]   = trim(end($arr));
            $and .=" and month >= '$arr[0]' and month <='$arr[1]'";
        }
        //排序
        $orderBy = $this->listSort(array(
            "search"  => $this->post('list_sort_key') ?: 'month',
            "sort" => $this->post('list_sort') ?: "desc",
            "array"   => array(),
        ));
        //获取查询结果
        $where = search(array("like" => $like, "=" => $equal)) . $and;
        $page = $this->page(array("table" => self::table, 'field'=>"distinct month","where" => $where, "order" =>$orderBy['orderBy']));
        static::rSet(self::$stid.self::page.'TotalSql',$page['fullSql']);
        //获取自定义字段参数
        $installSearch = $this->installSearch();
        $body          = [];
        //表格控件区
        $liButton = array("");
        //获取记录
        $url = root . "control/adIndex.html?cla=" . self::page;
        foreach ($page['array'] as $array) {
            //列表控件
            $dominate = array(
                'affair'=>array('title'=>'生成凭证','click'=>"layer('".self::page."','voucher',{month:'".$array['month']."'})"),
                "detail" => array("title" => self::title . "详情", "click" => "newIframe('" . self::title . "详情','" . $url . "&fun=detail&month=" . $array['month'] . "')"),
            );
            $total = find(array('table'=>self::table,"single"=>"month = '$array[month]' and isPay = 1",'field'=>"ifnull(sum(baseMoney),0) as baseMoney,ifnull(sum(jobMoney),0) as jobMoney,ifnull(sum(decMoney),0) as decMoney,ifnull(sum(fullAttendance),0) as fullAttendance,ifnull(sum(performance),0) as performance,ifnull(sum(insure),0) as insure,ifnull(sum(providentFund),0) as providentFund,ifnull(sum(personalTax),0) as personalTax,ifnull(sum(payMoney),0) as payMoney"));
            $liButton[] = $this->dominate($dominate);
            //本行初始化
            $row = [];
            foreach ($installSearch['key'] as $key) {
                switch ($key) {
                    case 'baseMoney':
                    case 'jobMoney':
                    case 'decMoney':
                    case 'fullAttendance':
                    case 'performance':
                    case 'insure':
                    case 'providentFund':
                    case 'personalTax':
                    case 'payMoney':
                        $row[] = $total[$key];
                        break;
                    default:
                        $row[] = isset($array[$key]) && $array[$key] ? $array[$key] : '';
                }
            }
            $body[] = $row;
        }
        //控件
        $button = "";
        //生成页面
        $li = $this->li(array(
            "body" => $body,
            "install" => $installSearch,
            "button" => array("html" => $liButton),
            "orderBySign" => $orderBy,
            "page" => $page['para'],
        ));
        //返回
        $json['html'] = $page['hint'] . $button . "<form name='listForm'>" . $li . "</form>".$this->js(). $page['button'] . clear;
        return json_encode($json, 320);
    }
    private function js(){
        return <<<eof
<script>
function navigetionTo(form){
    let month = $("[name='"+form+"'] [name='month']").val();
    let settingId = $("[name='"+form+"'] [name='settingId']").val();
    newIframe('录凭证',root+'control/adIndex.html?cla=voucherEdit&fun=home&month='+month+'&settingId='+settingId+'&method=salary')
    $('#salaryVoucher').hide()
}
</script>
eof;

    }
    public function voucher(){
        //生成表单
        $html = $this->layerEdit(
            array(
                "table" => array(
                    array(
                        must."模板：" =>idSelect(array('name'=>'settingId','class'=>'select text','title'=>'请选择','sqlForm'=>"salary_setting where coid = '".self::$coid."' and state = '启用' order by time asc",'sqlId'=>'id','sqlField'=>'name')),
                    ),
                ),
                'hidden'=>hidden(array('name'=>'month','value'=>$this->post('month')))
            )
        );
        //返回
        return $this->layer(array(
            "title" => "选择模板",
            "height" => 165,
            "html" => $html,
            'button'=>"<input onclick=\"navigetionTo('salaryVoucherForm')\" type='button' class='button' value='生成'>"
        ));
    }

    /*列表页-查询条件*/
    public function settingOptions($isAsync = true)
    {
        //生成查询表单
        $html = $this->tableShow([
            [
                [
                    "模板名称" => text(array('name'=>'templateName')),
                ]
            ]
        ],1);
        //返回
        if (!$isAsync) {
            return $html;
        } else {
            return json_encode(['html' => $html], 320);
        }
    }

    /**
     * 凭证配置
     * @return bool|string
     */
    public function setting()
    {
        $html = $this->settingOptions(false);
        $button = "<span class='spanButton li-btn-blue-bg' onclick=\"iframeReturnClose()\">返回</span>";
        if ($this->power(self::page, "edit")) {
            $button .= "<span class='spanButton' onclick=\"layer('" . self::page . "','settingPage',{id:'" . suiji() . "'})\">新增</span>";
            $button .= "<span class='spanButton' onclick=\"layer('{$this->get('cla')}', 'operate', {'act': 'delSetting'})\">删除</span>\n";
        }
        //返回
        return $this->homeFun($this->search($html, layout: 'pop', toolButton: $button));
    }

    public function settingSearch(): bool|string
    {
        //like查询数组
        $like = array(
            "name" => $this->post('templateName'),
        );
        //全等查询数组
        $equal = [
            'coid' => self::$coid,
        ];
        $where = search(array("like" => $like, "=" => $equal));
        $page = $this->page([
            "table" => "salary_setting",
            "where" => $where,
            "order" => "`updateTime` desc",
        ]);
        //获取表头
        $checkAll = $this->checkAll("visitForm", "listId");
        //获取表头
        $tr[] = [$checkAll, '模板名称', '凭证字', '状态'];
        //获取记录
        foreach ($page['array'] as $array) {
            //列表控件
            $dominate = array(
                "box" => array("name" => "listId", "value" => $array['id']),
                "edit" => array("title" => "编辑", "click" => "layer('" . self::page . "','settingPage',{id:'" . $array['id'] . "'})"),
            );
            $voucherWord = query('voucher_word',"id = '$array[voucherWordId]'");
            $tr[] = array(
                $this->dominate($dominate),
                $array['name'],
                $voucherWord['word'],
                $array['state'],
            );
        }
        $button = "";
        //控件
        $json['html'] = $page['hint'] . $button . "<form name='visitForm'>" . $this->tableMany(array("tr" => $tr)) . "</form>" . $page['button'];
        return json_encode($json, 320);
    }


    public function settingPage()
    {
        $id = $this->post('id');
        $info = query('salary_setting', "id = '$id'");
        $wordSelect = idSelect(array('name'=>'voucherWordId','class'=>'select','value'=>$info['voucherWordId'],'title'=>'请选择','sqlForm'=>"voucher_word where coid = '".self::$coid."'",'sqlId'=>'id','sqlField'=>'word'));
        $tr[] = ['会计科目','方向','取值','操作'];
        $all = find(array('table'=>'salary_setting_detail','where'=>"orderId = '$info[id]' order by list"));
        foreach ($all['array'] as $array){
            $direction = select(array('name'=>'direction[]','value'=>$array['direction'],'title'=>'请选择','option'=>['借','贷'],'class'=>'select'));
            $ruleOption = select(array('name'=>'rule[]','value'=>$array['rule'],'title'=>'请选择','option'=>explode('，',para('salarySettingRule')),'class'=>'select'));
            $subject = query('subject',"id = '$array[subjectId]'");
            $subjectSelect = text(array('name'=>'subjectName[]','value'=>$subject['code'].'-'.$subject['name'],'class'=>'text','id'=>$array['id'],'title'=>'请选择')).hidden(array('name'=>'subjectId[]','value'=>$array['subjectId'])).<<<eof
<script>
$("#{$array['id']}").bigAutocomplete({
    url:root + 'control/adIndex.html?cla=component&fun=getSubject',
    callback:function(data,e){
       e.siblings("input[name='subjectId[]']").val(data.id)
       e.parent().parent().find("[name='direction[]']").val(data.direction)
}}) 
</script>
eof;
            $tr[] = [$subjectSelect,$direction,$ruleOption,"<span class='del-row-button' onclick='decline(this)'>删除</span>".hidden(array('name'=>'mxId[]','value'=>$array['id']))];
        }
        $table = $this->tableMany(array('tr'=>$tr,'end'=>true,'button'=>true,'method'=>"addRow(this)"));
        //生成表单
        $html =<<<eof
<form name="templateForm">
<div style="padding:10px 20px">
    <div style="display: flex;flex-direction: row;justify-content: space-between">
        <div>模板名称：<input name="templateName" class="select" value="{$info['name']}" /></div>
        <div>凭证字：$wordSelect</div>
    </div>
    <div style="padding: 10px 0;margin-top: 10px;height: 330px;overflow: auto">
        $table
    </div>
    <input type="hidden" name="id" value="$id">
</div>
<script>
function addRow(e) {
    $.post(root+'control/adIndex.html?cla=salary&fun=addRow',{},function (res){
             $(e).parent().before(res.html);
    },'json');
}
</script>
</form>
eof;
        $button = "<input class='button' onclick=\"subForm('templateForm',root+'control/adIndex.html?cla=salary&fun=settingSave')\" type='button' value='保存'/>";

        //返回
        return $this->layer(array("title" => "凭证配置", "height" => 500, "width" => 800, "html" => $html, "button" => $button));
    }

    /**
     * 配置保存
     */
    public function settingSave(){
        $id = $this->post('id');

        $mxIds = $this->post('mxId');
        $directions = $this->post('direction');
        $ruleTexts = $this->post('rule');
        $subjectIds = $this->post('subjectId');

        $field = [
            'name'=>$this->post('templateName'),
            'voucherWordId'=>$this->post('voucherWordId'),
        ];
        $annotation = [
            'name' => '模板名称',
            'voucherWordId' => '凭证字',
        ];

        $rules = [
            'name' => 'required',
            'voucherWordId' => 'required',
        ];
        // 校验是否符合规则
        $vt = new \verify();
        $result = $vt->setAliases($annotation)->validate($field, $rules)->isOk();
        if ($result === false) {
            $json['warn'] = $vt->getErrs()[0];  // 多个规则提示最前面一条
            goto resp;
        }
        if (!$this->power(self::page, "edit")) {
            $json['warn'] = "你没有编辑" . self::title . "的权限";
        }elseif(static::total(array('table'=>'salary_setting','where'=>" and id !='$id' and name = '$field[name]' and coid = '".self::$coid."'")) >0){
            $json['warn'] ='已存在相同名称的模板';
        }elseif(static::is_null_array($mxIds)) {
            $json['warn'] = '请填写凭证规则';
        }elseif(static::is_null_array($subjectIds)){
            $json['warn'] = '请选择科目';
        }elseif(static::is_null_array($directions)){
            $json['warn'] = '请选择方向';
        }elseif(static::is_null_array($rules)){
            $json['warn'] = '请选择取值';
        } else {
            $this->startTrans();
            $where = " id = '$id' ";
            $voucherWord = query('voucher_word',"id = '$field[voucherWordId]'");
            $field['voucherWord'] = $voucherWord['word'];
            $info = query('salary_setting', $where);
            if (!$info['id']) {
                $field = array_merge($field, [
                    'id' => $id,
                    'coid' => self::$coid,
                    'state' => '启用',
                    'isDel'=>1
                ]);
                $json['warn'] = static::insert(["table" => 'salary_setting', "field" => $field]);
            } else {
                $json['warn'] = static::update([
                    "table" => 'salary_setting',
                    "field" => $field,
                    "where" => $where
                ]);
            }
            foreach ($mxIds as $k=>$mxId){
                $mx = query('salary_setting_detail',"id = '$mxId'");
                if (empty($mx['id'])){
                    $warn = static::insert(array(
                       'table'=>'salary_setting_detail',
                       'field'=>[
                           'id'=>$mxId,
                           'coid'=>self::$coid,
                           'orderId'=>$id,
                           'subjectId'=>$subjectIds[$k],
                           'direction'=>$directions[$k],
                           'rule'=>$ruleTexts[$k],
                       ]
                    ));
                }else{
                    $warn = static::update(array(
                        'table'=>'salary_setting_detail',
                        'field'=>[
                            'subjectId'=>$subjectIds[$k],
                            'direction'=>$directions[$k],
                            'rule'=>$ruleTexts[$k],
                        ],
                        'where'=>"id = '$mxId'"
                    ));
                }
                if (!in_array($warn,['新增成功','更新成功'])){
                    $json['warn'] = $warn;
                    break;
                }
            }
            if (in_array($json['warn'], ["新增成功", "更新成功"])) {
                $this->commitTrans();
                delete(array('table'=>'salary_setting_detail','where'=>"orderId = '$id' and id not in ('".implode("','",$mxIds)."')"));
                //添加日志
                $type = mb_substr($json['warn'], 0, 2, 'utf-8');
                $text = $this->control['name'] . $type . "了" . self::title . " id：【" . $id . '】';
                $this->logText(["type" => self::page, "text" => $text]);
                //返回
                $_SESSION['warn'] = $json['warn'];
                $json['warn'] = 2;
                $json['href'] = root . "control/adIndex.html?cla=" . $this->get('cla') . "&fun=setting";
            }else{
                $this->rollback();
            }
        }

        resp:
        return json_encode($json, 320);

    }

    /**
     * 添加一行
     * @return false|string
     */
    public function addRow(){
        $suiji = suiji();
        $direction = select(array('name'=>'direction[]','title'=>'请选择','option'=>['借','贷'],'class'=>'select'));
        $ruleOption = select(array('name'=>'rule[]','title'=>'请选择','option'=>explode('，',para('salarySettingRule')),'class'=>'select'));
        $subjectSelect = text(array('name'=>'subjectName[]','class'=>'text','id'=>$suiji,'title'=>'请选择')).hidden(array('name'=>'subjectId[]','value'=>'')).<<<eof
<script>
$("#{$suiji}").bigAutocomplete({
    url:root + 'control/adIndex.html?cla=component&fun=getSubject',
    callback:function(data,e){
       e.siblings("input[name='subjectId[]']").val(data.id)
        e.parent().parent().find("[name='direction[]']").val(data.direction)
}}) 
</script>
eof;

        $json['html'] = <<<eof
<tr>
    <td>$subjectSelect</td>
    <td>$direction</td>
    <td>$ruleOption</td>
    <td><input name="mxId[]" type="hidden" value="$suiji"/><span class="del-row-button" onclick="decline(this)">删除</span></td>
</tr>
eof;
        return json_encode($json,320);
    }
    /**
     * 导出
     */
    public function exportData()
    {
        if (!$this->power(self::page, 'export')) {
            $_SESSION['warn'] = '你还没有导出的权限';
        } else {
            $data = [];
            $sql = static::rGet(self::$stid.self::page.'TotalSql');
            $title = ["月份", "基本工资", "岗位工资", '考勤扣款', '全勤奖', '绩效工资', '社保扣款', '公积金扣款', '个税扣款', '实发小计'];
            $result = self::sqlFind($sql);
            if (is_array($result['array'])) {
                foreach ($result['array'] as $array) {
                    $total = find(array('table'=>self::table,"single"=>"month = '$array[month]' and isPay = 1",'field'=>"ifnull(sum(baseMoney),0) as baseMoney,ifnull(sum(jobMoney),0) as jobMoney,ifnull(sum(decMoney),0) as decMoney,ifnull(sum(fullAttendance),0) as fullAttendance,ifnull(sum(performance),0) as performance,ifnull(sum(insure),0) as insure,ifnull(sum(providentFund),0) as providentFund,ifnull(sum(personalTax),0) as personalTax,ifnull(sum(payMoney),0) as payMoney"));
                    $tr[] = array($array['month'], $total['baseMoney'],$total['jobMoney'],$total['decMoney'], $total['fullAttendance'],$total['performance'],$total['insure'],$total['providentFund'],$total['personalTax'],$total['payMoney']);
                }
            }
            $text = $this->control['name'] . "导出了工资表";
            $this->logText(["type" => self::page, "text" => $text]);
            $this->excelOut($title, $data, "工资表.xlsx");
        }
        header("Location:" . getenv("HTTP_REFERER"));
        exit(0);
    }

    /*详情页*/
    public function detail(): string
    {
        if (empty($this->get('month'))) {
            $html = '未找到月份';
        } else {
            //菜单
            $data = array(
                "id" => suiji(),
            );
            //生成表单
            $data['html'] = $this->tableShow(array(
                array(
                    array(
                        $this->score($this->get('month'))
                    ),
                ),
            ));
            //生成页面
            $html = $this->tab($data);
        }
        //返回
        return $html;
    }

    /*列表页-查询条件*/
    public function scoreOptions($isAsync = true, $data = [])
    {
        $month = !empty($data['month']??'') ? $data['month'] : $this->post('month');
        //生成查询表单
        $html = $this->tableShow([
            [
                [
                    "姓名" => text(["name" => "staffName"]),
                    "部门" => selectMultiple(["name" => "departmentId", 'table' => " department", 'sqlId' => 'id', 'sqlField' => 'name']).
                        hidden(array('name' => 'month', 'value' => $month)),
                ]
            ]
        ],1);
        //返回
        if (!$isAsync) {
            return $html;
        } else {
            return json_encode(['html' => $html], 320);
        }
    }

    /**
     * 工资表明细
     */
    public function score($month)
    {
        $html = $this->scoreOptions(false, ['month' => $month]);
        //控件
        $button = "<span class='spanButton li-btn-blue-bg' style='margin-left: 0' onclick=\"newIframe('工资表',root+'control/adIndex.html?cla=salary&fun=home')\">返回</span>";
        if ($this->power(self::page, "export")) {
            $button .= "  <a href='" . root . "control/adIndex.html?cla=" . $this->get('cla') . "&fun=exportPay'><span class='spanButton'>导出</span></a>\n";
        }
        return $this->search($html, layout: 'pop', toolButton: $button, searchOption: "{month:'$month'}");
    }

    public function detailSearch()
    {
        //全等查询数组
        $equal = array(
            "month" => $this->post('month'),//月份
        );
        $like = array(
            "name" => $this->post('staffName'),//员工
        );
        $and = " and isPay = 1";
        if (!empty($this->post('departmentId'))) {
            //部门
            $and .= " and jobId in (select id from job where departmentId = '{$this->post('departmentId')}') ";
        }
        //获取查询结果
        $where = search(array("=" => $equal, "like" => $like)) . $and;
        $page = $this->page(array("table" => self::table, "where" => $where, "order" => " time asc"));

        static::rSet(self::$stid.self::page.'sql',$page['fullSql']);
        //获取表头
        $tr[] = array("部门", "职位", "姓名", "月份", '基本工资', '岗位工资', '考勤扣款', '全勤奖', '绩效工资', '社保扣款', '公积金扣款', '个税扣款', '备注', '实发小计');
        //获取记录
        foreach ($page['array'] as $array) {
            //列表控件
            $job = query('job', " id = '$array[jobId]'");
            $department = query('department', " id = '$job[departmentId]'");
            //本行
            $tr[] = array($department['name'], $job['name'], $array['name'], $array['month'], $array['baseMoney'], $array['jobMoney'], $array['decMoney'], $array['fullAttendance'],
                $array['performance'], $array['insure'], $array['providentFund'], $array['personalTax'], $array['payText'], $array['payMoney']);
        }

        //返回
        $json['html'] = $page['hint'] . "<form name='recordForm'>" . space . $this->tableMany(array("tr" => $tr, "orderBySign" => '')) . "</form>" . $page['button'];
        return json_encode($json, 320);
    }
    /**
     * 导出已拨付
     */
    public function exportPay()
    {
        if (!$this->power(self::page, 'export')) {
            $_SESSION['warn'] = '你还没有导出的权限';
        } else {
            $data = [];
            $sql =static::rGet(self::$stid.self::page.'sql');
            $title = array("部门", "职位", "姓名", "月份", '基本工资', '岗位工资', '考勤扣款', '全勤奖', '绩效工资', '社保扣款', '公积金扣款', '个税扣款','备注', '实发小计');
            $result['array'] = sqlFind($sql);
            if (is_array($result['array'])) {
                foreach ($result['array'] as $array) {
                    //列表控件
                    $job = query('job', " id = '$array[jobId]'");
                    $department = query('department', " id = '$job[departmentId]'");
                    //本行
                    $data[] = array($department['name'], $job['name'], $array['name'], $array['month'], $array['baseMoney'], $array['jobMoney'], $array['decMoney'], $array['fullAttendance'],
                        $array['performance'], $array['insure'], $array['providentFund'], $array['personalTax'],$array['payText'], $array['payMoney']);
                }
            }
            $text = $this->control['name'] . "导出了工资表明细";
            $this->logText(["type" => self::page, "text" => $text]);
            $this->excelOut($title, $data, "工资表明细.xlsx");
        }
        header("Location:" . getenv("HTTP_REFERER"));
        exit(0);
    }


    // 操作中转
    public function operate()
    {
        $act = $this->post('act') ?? '';
        $pwd = false; // 需要密码
        $form = $power = '';
        switch ($act) {
            default:
                $act = 'del';
                $msg = '删除' . self::title;
                $title = self::page. 'Delete';
                $function = 'delete';
                $form = self::page . 'OperateForm, listForm, visitForm';
                $power = '';
                break;
        }
        if (!$this->power(self::page, $act)) {
            $_SESSION['warn'] = '你还没有' . $msg . '的权限';
            $json = [
                'warn' => 2,
                'href' => root . 'control/adIndex.html?cla=' . $this->get('cla') . '&fun=home',
            ];
        } else {
            return $this->confirm([
                'title' => $title,
                'function' => $function,
                'form' => $form,
                'power' => $power,
                'pwd' => $pwd,
            ]);
        }

        resp:
        return json_encode($json, 320);
    }
    /**
     * 删除
     * @return bool|string
     */
    public function delete()
    {
        $array = $this->post('listId') ?? $this->post('id');
        if (!$this->power(self::page, "del")) {
            $json['warn'] = "你没有删除的权限";
        } elseif (empty($array)) {
            $json['warn'] = "你一个数据都没有选择呢";
        } else {
            $text = "";
            $x = 0;
            $array = is_array($array) ? $array : [$array];
            foreach ($array as $id) {
                $info = query(self::table, " id = '$id' ");
                //最后删除基本参数
                delete(array("table" => 'salary_setting', "where" => " id = '$id' "));
                delete(array("table" => 'salary_setting_detail', "where" => " orderId = '$id' "));
                //返回
                $warn = "删除成功";
                $x++;
                $text .= self::title . "ID【" . $info['id'] . "】" . $warn . "。<br>";
            }
            //添加日志
            $text = $this->control['name'] . "删除了" . self::title . "，结果如下：<br>" . $text;
            $this->logText(array("type" => self::page, "text" => $text));
            $_SESSION['warn'] = "删除了" . $x . "个" . self::title . "，详情见系统日志。";
            $json['warn'] = 2;
            $json['href'] = root . "control/adIndex.html?cla=" . $this->get('cla') . "&fun=home";
        }
        return json_encode($json, 320);
    }
}
